<template>
    <div id="score-query">
        <p v-if="!queryValid"> 初审成绩还未发布</p>
        <!-- 成绩显示区域 -->
        <div v-if="queryValid">
                
                <el-descriptions title="初试成绩" :column="2"  border>
                    <el-descriptions-item label="参赛者Id">{{score.prjConid}}</el-descriptions-item>
                    <el-descriptions-item label="作品名字">{{score.prjRealname}}</el-descriptions-item>
                    <el-descriptions-item label="作品链接">
                        <el-link :href="score.prjUrl"  :underline="false">下载文件</el-link>
                        
                    </el-descriptions-item>
                    <el-descriptions-item label="作品得分"> {{score.prjScore}} </el-descriptions-item>
                    <el-descriptions-item label="结果">
                        <el-tag size="medium " v-if="score.prjStatus==1||score.prjStatus==4||score.prjStatus ==3">通过初审</el-tag>
                        <el-tag size="medium " v-if="score.prjStatus==2">未通过初审</el-tag>
                    </el-descriptions-item>
                </el-descriptions>    
        </div>
        <br>
        <br>
        <p v-if="!finalqueryValid"> 终审成绩还未发布</p>
        <!-- 成绩显示区域 -->
        <p> {{finalContent}}</p>
        <div v-if="finalqueryValid && finalscore.prjStatus != 2">
        
            <el-descriptions title="终审成绩" :column="2" border>
                <el-descriptions-item label="参赛者Id">{{finalscore.prjConid}}</el-descriptions-item>
                <el-descriptions-item label="作品名字">{{finalscore.prjRealname}}</el-descriptions-item>
                <el-descriptions-item label="作品链接">
                    <el-link :href="finalscore.prjUrl" :underline="false">下载文件</el-link>
        
                </el-descriptions-item>
                <el-descriptions-item label="作品得分"> {{finalscore.prjScore}} </el-descriptions-item>
                <el-descriptions-item label="结果">
                    <el-tag size="medium " v-if="finalscore.prjStatus==3">通过终审</el-tag>
                    <el-tag size="medium " v-if="finalscore.prjStatus==4">未通过终审</el-tag>
                </el-descriptions-item>
            </el-descriptions>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                queryForm: {
                    conId: ''
                },
                finalContent:'',
                queryValid:false,
                finalqueryValid:false,
                finalscore:{},
                result:'',
                score: [{
                    prjIndex:'',
                    prjConid:         "",
                    prjRealname:      "",
                    prjVirtname:      "",
                    prjUrl:           "",
                    prjCreatetime:    "",
                    prjUpdatetime:    "",
                    prjScore:        NaN,
                    prjPublicfirstgrad: null,
                    prjFinalscore:        NaN,
                    prjPublicfinalgrad: null,
                    prjStatus: "",
                }] // 用于存储查询到的成绩信息
            };
        },
        methods: {
            async fetchData() {
                await this.$axios({
                    method: 'post',
                    url: "http://localhost:8080/project/havepublishfirstGrade",
                }).then(res => {
                    if (res.data.data != 0) {
                        this.queryValid = false;
                    }else{
                        
                        this.queryForm.conId = this.$store.state.userdata.userId;
                        this.$axios({
                            method: 'post',
                            url: "http://localhost:8080/project/firstscorequery",
                            data: this.queryForm,
                            headers: {
                                'Content-Type': 'multipart/form-data'
                            }
                        }).then(res => {
                            if (res.data.code ==1) {
                                this.queryValid = true;
                                this.score = res.data.data;
                                console.log(this.score);
                                
                            } else {
                                this.$message.error(res.data.msg);
                            }
                        })
                    }
                })
                await this.$axios({
                    method: 'post',
                    url: "http://localhost:8080/project/havepublishfinalscore",
                }).then(res => {
                    if (res.data.data != 0) {
                        this.finalqueryValid = false;
                    } else {

                        this.queryForm.conId = this.$store.state.userdata.userId;
                        this.$axios({
                            method: 'post',
                            url: "http://localhost:8080/project/finalscorequery",
                            data: this.queryForm,
                            headers: {
                                'Content-Type': 'multipart/form-data'
                            }
                        }).then(res => {
                            if (res.data.code == 1) {
                                if(res.data.data.prjStatus===3){
                                    this.finalContent = "恭喜通过终审"
                                }
                                if (res.data.data.prjStatus === 2) {
                                    this.finalContent = "很遗憾你没通过初审"
                                }
                                if (res.data.data.prjStatus === 4) {
                                    this.finalContent = "很遗憾你没通过终审"
                                }
                                this.finalqueryValid = true;
                                this.finalscore = res.data.data;
                                console.log(this.finalscore);

                            } else {
                                this.$message.error(res.data.msg);
                            }
                        })
                    }
                })
            },
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        // 这里使用axios或其他HTTP库发送请求到后端获取成绩信息
                        // 假设你使用axios，且你的API地址为'/api/scores'
                        this.$axios({
                            method: 'post',
                            url: "http://localhost:8080/project/firstscorequery",
                            data:this.queryForm,
                            headers: {
                                'Content-Type': 'multipart/form-data'
                            }
                        }).then(res => {
                            if (res.data.data != 0) {
                                this.queryValid = false;
                            } else {
                                this.queryValid = true;
                            }
                        })
                    } else {
                        console.log('表单验证失败！');
                        return false;
                    }
                });
            }
        },
        mounted(){
            this.fetchData();
        }
    };
</script>

<style scoped>
    /* 可以在这里添加自定义样式 */
</style>